package com.rory.service.serviceInterfaceImpl;

import com.rory.dao.expand.MenuDao;
import com.rory.dao.generate.MenuMapper;
import com.rory.entity.expand.MenuModel;
import com.rory.entity.generate.Menu;
import com.rory.service.CrudService;
import com.rory.service.serviceInterface.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * class: MenuServiceImpl.
 * Created by Rory on 2016/11/23.
 * use:  .
 * other:  .
 */
@Service
public class MenuServiceImpl extends CrudService<MenuMapper, Menu> implements MenuService {

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    private MenuDao menuDao;

    @Override
    public List<MenuModel> loadMenu(Integer roleId) {
        //思路: 单个菜单下有一个子菜单集合,先查出大菜单,根据大菜单查小菜单,把小菜单推到大菜单的小菜单集合下
        List<MenuModel> menuModels = menuDao.searhMenuByRoleIdParent(roleId);
        for (MenuModel menuModel : menuModels) {
            List<Menu> menus = menuDao.searhMenuByRoleIdChild(roleId, menuModel.getId());
            menuModel.setListSize(menus.size());
            menuModel.setMenuList(menus);
        }
        return menuModels;
    }
}
